package com.example.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.entity.Elevator;
import com.example.ext.entity.ExtElevator;
import com.example.service.ElevatorService;
import com.example.util.HttpRequestUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by youkun on 2017/10/5.
 */
@RestController
public class ElevatorController {
    @Autowired
    private ElevatorService elevatorService;

    @ApiOperation(value = "查询电梯列表的信息",notes = "查询电梯列表的信息")
    @RequestMapping(value="api/elevator/getList",method = RequestMethod.POST)
    Map<String,Object> getElevatorList(@RequestBody ExtElevator extElevator){

        return elevatorService.queryList(extElevator);
    }

    @PostMapping("api/elevator/queryElevatorList")
    Map<String,Object> queryElevatorList(@RequestBody ExtElevator extElevator){
        return elevatorService.queryElevatorList(extElevator);
    }

    @ApiOperation(value = "修改所属分局",notes = "修改所属分局")
    @PostMapping("api/elevator/updateChessboard")
    Map<String,Object>updateChessboard(@RequestBody Map<String, Object> param){

        return elevatorService.updateChessboard(param);
    }

    @ApiOperation(value = "查询电梯列表的信息",notes = "查询电梯列表的信息")
    @RequestMapping(value="api/elevator/getMaintList",method = RequestMethod.POST)
    Map<String,Object> getMaintElevatorList(@RequestBody Map<String, Object> extElevator){

        return elevatorService.queryMaintList(extElevator);
    }
    @ApiOperation(value = "查询电梯列表的信息",notes = "查询电梯列表的信息")
    @RequestMapping(value="api/elevator/getJgList",method = RequestMethod.POST)
    Map<String,Object> getJgElevatorList(@RequestBody Map<String, Object> extElevator){

        return elevatorService.queryJgList(extElevator);
    }
    @PostMapping("api/elevator/updateElevatorType")
    Map<String,Object> updateElevatorType(@RequestBody Map<String,Object> map){
        return elevatorService.updateElevatorType(map);
    }

    @ApiOperation(value = "添加电梯的信息",notes = "添加电梯的信息")
    @RequestMapping(value="api/elevator/add",method = RequestMethod.POST)
    Map<String,Object> addElevator(@RequestBody Map<String,Object> map){

        return elevatorService.add(map);
    }

    @ApiOperation(value = "修改电梯的信息",notes = "修改电梯的信息")
    @RequestMapping(value="api/elevator/update",method = RequestMethod.POST)
    Map<String,Object> updateElevator(@RequestBody Elevator elevator){

        return elevatorService.update(elevator);
    }

    @ApiOperation(value = "查询某个电梯的信息",notes = "根据用户id获取电梯详细信息")
    @RequestMapping(value="api/elevator/{id}",method = RequestMethod.POST)
    Map<String,Object> findUserFunction(@PathVariable String id) {

        return elevatorService.queryById(id);
    }

    @ApiOperation(value = "查询某个电梯的信息",notes = "根据用户id获取电梯详细信息")
    @RequestMapping(value="api/userElevator/{id}",method = RequestMethod.POST)
    Map<String,Object> findUserElevator(@PathVariable String id) {

        return elevatorService.queryById(id);
    }


    @ApiOperation(value = "查询某个电梯的信息",notes = "根据设备编号获取电梯详细信息")
    @RequestMapping(value="api/uploadPublicUserElevator/{id}",method = RequestMethod.POST)
    Map<String,Object> publicUserElevator(@PathVariable String id) {

        return elevatorService.publicUserElevator(id);
    }


    @ApiOperation(value = "删除电梯的信息",notes = "删除电梯的信息")
    @RequestMapping(value="api/elevator/delete",method = RequestMethod.POST)
    Map<String,Object> delete(@RequestBody Map<String, Object> param) {
        List<String> ids = (List<String>)param.get("ids");
        return elevatorService.delete(ids);
    }
    @ApiOperation(value = "批量删除电梯的信息",notes = "批量删除电梯的信息")
    @PostMapping(value = "api/elevator/batchDelete")
    Map<String,Object>batchDelete(@RequestBody Map<String,Object> param){
        List<String> ids = (List<String>)param.get("ids");
        return elevatorService.batchDelete(ids);
    }


    @ApiOperation(value = "导入电梯的信息",notes = "导入电梯的信息")
    @RequestMapping(value="elevator/import",method = RequestMethod.POST)
    Map<String,Object> importElevator(@RequestBody MultipartFile file ,@RequestParam("partyId") String partyId){

        return elevatorService.importElevator(file,partyId);
    }

    @ApiOperation(value = "更新电梯经纬度",notes = "更新电梯经纬度")
    @RequestMapping(value="api/elevator/updateLatLng",method = RequestMethod.POST)
    Map<String,Object> updateLatLng(@RequestBody Map<String, Object> param) {
        return elevatorService.updateLatLng(param);
    }

    @ApiOperation(value = "获取电梯经纬度",notes = "获取电梯经纬度")
    @RequestMapping(value="api/elevator/getLatLng",method = RequestMethod.POST)
    Map<String,Object> getLatLng(@RequestBody Map<String, Object> param) {
        return elevatorService.getLatLng(param);
    }

    @ApiOperation(value = "更新电梯场所",notes = "更新电梯场所")
    @RequestMapping(value="api/elevator/updateElevatorPlace",method = RequestMethod.POST)
    Map<String,Object> updateElevatorPlace(@RequestBody Map<String, Object> param) {
        return elevatorService.updateElevatorPlace(param);
    }

    @ApiOperation(value = "批量更新电梯的安全管理员",notes = "批量更新电梯的安全管理员")
    @RequestMapping(value="api/elevator/updateSafeUser",method = RequestMethod.POST)
    Map<String,Object> updateSafeUser(@RequestBody Map<String, Object> param) {
        return elevatorService.updateSafeUser(param);
    }

    @ApiOperation(value = "查询电梯信息",notes = "根据电梯编号查询电梯信息")
    @RequestMapping(value="api/elevator/getElevatorInfoByNum",method = RequestMethod.POST)
    Map<String,Object> getElevatorInfoByNum(@RequestBody Map<String, Object> param){
        return elevatorService.getElevatorInfoByNum(param);
    }

    @ApiOperation(value = "查询电梯信息",notes = "根据96333编号查询电梯信息")
    @PostMapping(value="api/elevator/getEleInfoBy96333Code")
    Map<String,Object> getEleInfoBy96333Code(@RequestBody Map<String, Object> param){
        Map<String, Object> maintenanceMap = new HashMap<>();
        maintenanceMap.put("service", "DeviceMngService");
        maintenanceMap.put("action", "getDeviceInfoForPrintp6333WithCode2DScanResult");
        List a = new ArrayList();
        a.add("uid=3205000005");
        a.add(param.get("devId")+"");
        maintenanceMap.put("params", a);
        String httpUrl = "http://58.211.125.90:10086/bpalerc_sz/hsf/ServiceEntrance";
        JSONObject jsonObject = new JSONObject(maintenanceMap);
        String res = HttpRequestUtils.sendPost(httpUrl, jsonObject, null);
        JSONObject json = JSONObject.parseObject(res);
        String retValue = json.getString("retValue");
        JSONObject data = (JSONObject)JSONArray.parseArray(retValue).get(0);
        String registration_code = data.get("registration_code")+"";
        Map ss = new HashMap();
        ss.put("elevatorNum",registration_code);
        return elevatorService.getElevatorInfoByNum(ss);
    }

    @ApiOperation(value = "双随机一公开查询电梯信息",notes = "双随机一公开查询电梯信息")
    @RequestMapping(value="api/elevator/getElevatorList",method = RequestMethod.POST)
    Map<String,Object> getElevatorList(@RequestBody Map<String, Object> param){
        return elevatorService.getElevatorList(param);
    }

    @ApiOperation(value = "按需维保查询电梯台账",notes = "按需维保查询电梯台账")
    @RequestMapping(value="api/elevator/demandMaintGetElevators",method = RequestMethod.POST)
    Map<String,Object> demandMaintGetElevators(@RequestBody ExtElevator extElevator){
        return elevatorService.demandMaintGetElevators(extElevator);
    }

    @ApiOperation(value = "无纸化维保查询电梯台账",notes = "按需维保查询电梯台账")
    @RequestMapping(value="api/elevator/paperlessMaintGetElevators",method = RequestMethod.POST)
    Map<String,Object> paperlessMaintGetElevators(@RequestBody ExtElevator elevator){
        return elevatorService.paperlessMaintGetElevators(elevator);
    }

    @ApiOperation(value = "查询电梯台账制造单位",notes = "查询电梯台账制造单位")
    @RequestMapping(value="api/elevator/queryCreateCompanys",method = RequestMethod.POST)
    Map<String,Object> queryCreateCompanys(@RequestBody ExtElevator extElevator){
        return elevatorService.queryCreateCompanys(extElevator);
    }

    @ApiOperation(value = "委托检测查询电梯台账",notes = "委托检测查询电梯台账")
    @RequestMapping(value="api/elevator/detectionGetElevator",method = RequestMethod.POST)
    Map<String,Object> detectionGetElevator(@RequestBody Map<String, Object> param){
        return elevatorService.detectionGetElevator(param);
    }

    /**
     * 批量更新初始化数据
     * @param param
     * @return
     */
    @ApiOperation(value = "通过test表，批量更新初始化数据",notes = "通过test表，批量更新初始化数据")
    @RequestMapping(value="api/elevator/updateFlag",method = RequestMethod.POST)
    Map<String,Object> updateFlag(@RequestBody Map<String, Object> param){
        return elevatorService.updateFlag(param);
    }

    /**
     * 批量更新电梯台账关联的所属单位
     * @param param
     * @return
     */
    @ApiOperation(value = "通过elevator_unit表，批量更新初始化数据",notes = "通过elevator_unit表，批量更新初始化数据")
    @RequestMapping(value="api/elevator/elevatorUnit",method = RequestMethod.POST)
    Map<String,Object> elevatorUnit(@RequestBody Map<String, Object> param){
        return elevatorService.elevatorUnit(param);
    }


    /**
     *  @Description:查询无主电梯的信息
     * @Date:2019/09/29
     * @Author:lile
     * @param elevator
     * @return
     */
    @ApiOperation(value = "查询无主电梯信息",notes = "查询无主电梯信息")
    @RequestMapping(value="api/elevator/noownerElevatorQuery",method = RequestMethod.POST)
    Map<String,Object> noownerElevatorQuery(@RequestBody ExtElevator elevator){
        return elevatorService.noownerElevatorQuery(elevator);
    }


    @ApiOperation(value = "修改无主电梯的信息",notes = "修改无主电梯的信息")
    @RequestMapping(value="api/elevator/noownerElevatorUpdate",method = RequestMethod.POST)
    Map<String,Object> noownerElevatorUpdate(@RequestBody Map<String, Object> param){
        return elevatorService.noownerElevatorUpdate(param);
    }


    @ApiOperation(value = "查询未确认维保工单的信息",notes = "查询未确认维保工单的信息")
    @RequestMapping(value="api/elevator/unconfirmedMaintenance",method = RequestMethod.POST)
    Map<String,Object> unconfirmedMaintenance(@RequestBody Map<String, Object> param){
        return elevatorService.unconfirmedMaintenance(param);
    }

    @ApiOperation(value = "发送未确认维保工单的信息",notes = "发送未确认维保工单的信息")
    @RequestMapping(value="api/elevator/sendNoticeUnconfirmed",method = RequestMethod.POST)
    Map<String,Object> sendNoticeUnconfirmed(@RequestBody List<Map<String, Object>> param){

        return elevatorService.sendNoticeUnconfirmed(param);
    }

    @ApiOperation(value = "使用单位查询未确认维保工单的信息",notes = "使用单位查询未确认维保工单的信息")
    @RequestMapping(value="api/elevator/needconfirmedMaintenance",method = RequestMethod.POST)
    Map<String,Object> queryNeedconfirmedMaintenance(@RequestBody Map<String, Object> param){
        return elevatorService.queryNeedconfirmedMaintenance(param);
    }

    @ApiOperation(value = "使用单位查询未确认维保工单的信息",notes = "使用单位查询未确认维保工单的信息")
    @RequestMapping(value="api/elevator/sureUnconfirmed",method = RequestMethod.POST)
    Map<String,Object> sureUnconfirmed(@RequestBody Map map){
        return elevatorService.sureUnconfirmed(map);
    }

    @ApiOperation(value = "获取电梯经纬度",notes = "获取电梯经纬度")
    @RequestMapping(value="api/elevator/getLatLngByLevel",method = RequestMethod.POST)
    Map<String,Object> getLatLngByLevel(@RequestBody Map<String, Object> param) {
        return elevatorService.getLatLngByLevel(param);
    }

}
